﻿<extend name="Public:base" />
<block name="title"><title>企业资料</title></block>
<block name="header_styles">
    <style type="text/css">
        .user-pic {
            text-align: center;
        }

        iframe.photo {
            display: block;
            margin: auto;
        }
    </style>
</block>
<block name="main">
    <div class="row">
        <div class="col-xs-3">
            <div class="column-sidebar">
                <include file="Public:LeftMenu" />
            </div>
        </div>
        <div class="col-xs-9">
            <div class="column-main">
                <div class="section">
                    <div class="section-title">
                        <a href="javascript:void(0);" class="info-actions pull-right" id="btnEditPic" title="编辑"><i class="fa fa-edit"></i></a>&nbsp;企业LOGO
                    </div>
                    <div class="section-content">
                        <br />
                        <div id="phPreviewPic">
                            <div class="user-pic">
                                <img src="__APP__/{:toTalentPhoto($userinfo['photo'],$userinfo['utype'])}" alt="" />
                            </div>
                        </div>
                        <div id="phEditablePic" style="display: none;">
                            <iframe src="{:U('/Index/sp')}" scrolling="no" frameborder="0" width="502" height="360" class="photo"></iframe>
                            <input type="hidden" id="userpic" />
                            <div class="text-center" style="padding:10px 0px;">
                                <button type="button" id="btnSavePhoto" class="btn btn-success">保存头像</button>
                                <br />
                                <br />
                            </div>
                        </div>
                    </div>
                </div>
                <div class="section">
                    <div class="section-title">
                        <a href="javascript:void(0);" class="info-actions pull-right" id="btnEditBaseInfo" title="编辑"><i class="fa fa-edit"></i></a>&nbsp;基本信息
                    </div>
                    <div class="section-content">
                        <br />
                        <div id="phPreviewBaseInfo" class="form-horizontal label-align-left">

                            <div class="row">
                                <div class="col-xs-6">
                                    <div class="form-group">
                                        <label class="control-label col-xs-4">企&nbsp;业&nbsp;全&nbsp;称：</label>
                                        <div class="col-xs-8">
                                            <p class="form-control-static" id="lblRealname">{$userinfo.nickname}</p>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-xs-6">
                                    <div class="form-group">
                                        <label class="control-label col-xs-4">企&nbsp;业&nbsp;简&nbsp;称：</label>
                                        <div class="col-xs-8">
                                            <p class="form-control-static" id="lblNickname">{$userinfo.shortname}</p>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-xs-6">
                                    <div class="form-group">
                                        <label class="control-label col-xs-4">所&nbsp;&nbsp;&nbsp;在&nbsp;&nbsp;&nbsp;地：</label>
                                        <div class="col-xs-8">
                                            <p class="form-control-static" id="lblAddress">
                                                {$userinfo.address}
                                            </p>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-xs-6">
                                    <div class="form-group">
                                        <label class="control-label col-xs-4">所&nbsp;处&nbsp;行&nbsp;业：</label>
                                        <div class="col-xs-8">
                                            <p class="form-control-static" id="lblWeibo">
                                                {$userinfo.industry}
                                            </p>
                                        </div>
                                    </div>
                                </div>

                            </div>
                            <div class="row">
                                <div class="col-xs-6">
                                    <div class="form-group">
                                        <label class="control-label col-xs-4">联&nbsp;&nbsp;&nbsp;系&nbsp;&nbsp;&nbsp;人：</label>
                                        <div class="col-xs-8">
                                            <p class="form-control-static" id="lblMobile">
                                                {$userinfo.contactname}
                                            </p>
                                        </div>
                                    </div>
                                </div>

                                <div class="col-xs-6">
                                    <div class="form-group">
                                        <label class="control-label col-xs-4">联&nbsp;系&nbsp;邮&nbsp;箱：</label>
                                        <div class="col-xs-8">
                                            <p class="form-control-static" id="lblMobile">
                                                {$userinfo.contactemail}
                                            </p>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-xs-6">
                                    <div class="form-group">
                                        <label class="control-label col-xs-4">移&nbsp;动&nbsp;电&nbsp;话：</label>
                                        <div class="col-xs-8">
                                            <p class="form-control-static" id="lblMobile">
                                                {$userinfo.mobile}
                                            </p>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-xs-6">
                                    <div class="form-group">
                                        <label class="control-label col-xs-4">固&nbsp;定&nbsp;电&nbsp;话：</label>
                                        <div class="col-xs-8">
                                            <p class="form-control-static">
                                                {$userinfo.telephone}
                                            </p>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-xs-12">
                                    <div class="form-group">
                                        <label class="control-label col-xs-2">
                                            官&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;网：
                                        </label>
                                        <div class="col-xs-10">
                                            <p class="form-control-static" id="lblBlog">
                                                {$userinfo.website}
                                            </p>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-xs-12">
                                    <div class="form-group">
                                        <label class="control-label col-xs-2">企&nbsp;业&nbsp;简&nbsp;介：</label>
                                        <div class="col-xs-10">
                                            <p class="form-control-static" id="lblBlog">
                                                {$userinfo.intro}
                                            </p>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-xs-12">
                                    <div class="form-group">
                                        <label class="control-label col-xs-2">企&nbsp;业&nbsp;文&nbsp;化：</label>
                                        <div class="col-xs-10">
                                            <p class="form-control-static" id="lblBlog">
                                                {$userinfo.culture}
                                            </p>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div id="phEditableBaseInfo" class="form-horizontal label-align-left" style="display:none;">
                            <form id="formBaseInfo" method="post">
                                <div class="row">
                                    <div class="col-xs-6">
                                        <div class="form-group">
                                            <label class="control-label col-xs-4">企&nbsp;业&nbsp;全&nbsp;称：</label>
                                            <div class="col-xs-8">
                                                <input type="text" class="form-control"
                                                       data-val="true" data-val-required="请填写企业全称"
                                                       name="nickname" id="nickname" value="{$userinfo.nickname}" maxlength="30" />
                                                <span data-valmsg-for="nickname" data-valmsg-replace="true"></span>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="col-xs-6">
                                        <div class="form-group">
                                            <label class="control-label col-xs-4">企&nbsp;业&nbsp;简&nbsp;称：</label>
                                            <div class="col-xs-8">
                                                <input type="text" class="form-control" id="shortname" name="shortname"
                                                       maxlength="30"
                                                       data-val="true" data-val-required="请填写企业简称" value="{$userinfo.shortname}"/>
                                                <span data-valmsg-for="shortname" data-valmsg-replace="true"></span>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-xs-6">
                                        <div class="form-group">
                                            <label class="control-label col-xs-4">所&nbsp;&nbsp;&nbsp;在&nbsp;&nbsp;&nbsp;地：</label>
                                            <div class="col-xs-8 form-inline">
                                                <input type="hidden" name="address" id="address" value="{$userinfo.address}" />
                                                <select name="province" id="ddlProvince"
                                                        style="margin-right: 7px;"
                                                        class="form-control"
                                                        data-val="true" data-val-required="地址不能为空"></select>
                                                <select name="city" id="ddlCity" class="form-control" style="width:123px;">
                                                    <option value="">请选择</option>
                                                </select>
                                                <span data-valmsg-for="province" data-valmsg-replace="true"></span>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="col-xs-6">
                                        <div class="form-group">
                                            <label class="control-label col-xs-4">
                                                所&nbsp;处&nbsp;行&nbsp;业：
                                            </label>
                                            <div class="col-xs-8">
                                                <input type="text" class="form-control" 
                                                       id="industry" name="industry"
                                                       data-val="true" data-val-required="所在行业不能为空"
                                                       value="{$userinfo.industry}" maxlength="20" />
                                                <span data-valmsg-for="industry" data-valmsg-replace="true"></span>
                                            </div>
                                        </div>
                                    </div>

                                </div>
                                <div class="row">
                                    <div class="col-xs-6">
                                        <div class="form-group">
                                            <label class="control-label col-xs-4">联&nbsp;&nbsp;系&nbsp;&nbsp;&nbsp;人：</label>
                                            <div class="col-xs-8">
                                                <input type="text" class="form-control" id="contactname" name="contactname" value="{$userinfo.contactname}"
                                                       data-val="true" data-val-required="联系人不能为空" maxlength="5" />
                                                <span data-valmsg-for="contactname" data-valmsg-replace="true"></span>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-xs-6">
                                        <div class="form-group">
                                            <label class="control-label col-xs-4">联&nbsp;系&nbsp;邮&nbsp;箱：</label>
                                            <div class="col-xs-8">
                                                <input type="text" class="form-control" id="contactemail" name="contactemail" value="{$userinfo.contactemail}"
                                                       data-val="true" data-val-required="联系人邮箱不能为空"
                                                       data-val-regex="请填写正确的邮箱地址"
                                                       data-val-regex-pattern="^\\w+([\\.-]?\\w+)*@([a-zA-Z0-9_-])+((\\.[a-zA-Z0-9_-]{2,3}){1,2})$" />
                                                <span data-valmsg-for="contactemail" data-valmsg-replace="true"></span>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-xs-6">
                                        <div class="form-group">
                                            <label class="control-label col-xs-4">移&nbsp;动&nbsp;电&nbsp;话：</label>
                                            <div class="col-xs-8">
                                                <input type="text" class="form-control" id="mobile" name="mobile" value="{$userinfo.mobile}"
                                                       data-val="true" data-val-required="联系人移动电话不能为空" data-val-regex="无效电话号码" data-val-regex-pattern="((\\d{2,5}-\\d{7,8})|(^(1[34587])[0-9]\\d{8}$))" maxlength="20" />
                                                <span data-valmsg-for="mobile" data-valmsg-replace="true"></span>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-xs-6">
                                        <div class="form-group">
                                            <label class="control-label col-xs-4">固&nbsp;定&nbsp;电&nbsp;话：</label>
                                            <div class="col-xs-8">
                                                <input type="text" class="form-control" id="telephone" name="telephone" value="{$userinfo.telephone}" placeholder="xxxx-xxxxxxxx"
                                                       data-val-regex="无效电话号码" data-val-regex-pattern="([0-9]{3,4}-)?[0-9]{7,8}"
                                                       data-val="true" data-val-required="联系人固定电话不能为空" />
                                                <span data-valmsg-for="telephone" data-valmsg-replace="true"></span>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-xs-12">
                                        <div class="form-group">
                                            <label class="control-label col-xs-2">
                                                官&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;网：
                                            </label>
                                            <div class="col-xs-10">
                                                <input type="text" class="form-control" id="website" name="website" value="{$userinfo.website}" maxlength="30" />
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-xs-12">
                                        <div class="form-group">
                                            <label class="control-label col-xs-2">
                                                企&nbsp;业&nbsp;简&nbsp;介：
                                            </label>
                                            <div class="col-xs-10">
                                                <textarea type="text" class="form-control" id="intro" name="intro" rows="5" maxlength="200">{$userinfo.intro}</textarea>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-xs-12">
                                        <div class="form-group">
                                            <label class="control-label col-xs-2">
                                                企&nbsp;业&nbsp;文&nbsp;化：
                                            </label>
                                            <div class="col-xs-10">
                                                <textarea type="text" class="form-control" id="culture" name="culture" rows="5" maxlength="200">{$userinfo.culture}</textarea>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-xs-12 text-center">
                                        <button type="submit" class="btn btn-success" id="btnSaveBaseInfo">保存</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</block>
<block name="footer_scripts">
    <script type="text/javascript">
        function photoCropCompleted(url) {
            $("#userpic").val(url);
        }
    </script>
    <script type="text/javascript">
        require(["jquery", "modules/message", "jquery.validate", "libraries/location_cn", "libraries/common"], function ($, messageBox) {
            function initCities(province, selected) {
                if (selected != "" && province != "") {
                    $("#ddlCity option").remove();
                    var selectCities = cities[province];
                    for (var i = 0; i < selectCities.length; i++) {
                        if (selectCities[i] == selected) {
                            $("#ddlCity").append("<option selected value='" + selectCities[i] + "'>" + selectCities[i] + "</option>");
                        } else {
                            $("#ddlCity").append("<option value='" + selectCities[i] + "'>" + selectCities[i] + "</option>");
                        }
                    }
                }
                else {
                    $("#ddlCity option").remove();
                    $("#ddlCity").append("<option value=''>请选择</option>");
                }
                $("#ddlCity").change(function () {
                    $("#address").val($("#ddlProvince").val() + "," + $("#ddlCity").val());
                });
            }

            $(function () {
                bindDropDownListData("#ddlYears", 1935, new Date().getFullYear(), onYearChange);
                bindDropDownListData("#ddlMonths", 1, 12, onYearChange);
                bindDropDownListData("#ddlDays", 1, 31);

                //var about = $('#about').val();
                //console.log(about);
                //$("#lblAbout").html(about.replace(/\n/g, "<br/>"));
                var address = "{$userinfo.address}";
                var prnAndCity = address.split(',');
                var province = prnAndCity[0];
                var city = prnAndCity[1];
                for (var item in cities) {
                    if (province == item) {
                        $("#ddlProvince").append("<option selected value='" + item + "'>" + item + "</option>");
                    } else if (item == "请选择") {
                        $("#ddlProvince").append("<option value=''>" + item + "</option>");
                    } else {
                        $("#ddlProvince").append("<option value='" + item + "'>" + item + "</option>");
                    }
                }

                initCities(province, city);

                $("#ddlProvince").change(function () {
                    initCities($(this).val());
                    var province = $("#ddlProvince").get(0).value;
                    var city = $("#ddlCity").get(0).value;
                    $("#address").val(province + "," + city);
                });

                $("#btnEditBaseInfo").click(function () {
                    if ($(this).attr("title") == "编辑") {
                        $(this).attr("title", "取消");
                        $(this).html("<i class='fa fa-times'></i>");
                        $("#phPreviewBaseInfo").hide();
                        $("#phEditableBaseInfo").fadeIn();
                        $("#nickname").focus();
                    } else {
                        $(this).attr("title", "编辑");
                        $(this).html("<i class='fa fa-edit'></i>");
                        $("#phPreviewBaseInfo").fadeIn();
                        $("#phEditableBaseInfo").hide();
                    }
                });

                $("#btnEditPic").click(function () {
                    if ($(this).attr("title") == "编辑") {
                        $(this).attr("title", "取消");
                        $(this).html("<i class='fa fa-times'></i>");
                        $("#phPreviewPic").hide();
                        $("#phEditablePic").fadeIn();
                        $("#nickname").focus();
                    } else {
                        $(this).attr("title", "编辑");
                        $(this).html("<i class='fa fa-edit'></i>");
                        $("#phPreviewPic").fadeIn();
                        $("#phEditablePic").hide();
                    }
                });

                $("#btnEditIntro").click(function () {
                    if ($(this).attr("title") == "编辑") {
                        $(this).attr("title", "取消");
                        $(this).html("<i class='fa fa-times'></i>");
                        $("#phPreviewIntro").hide();
                        $("#phEditableIntro").fadeIn();
                    } else {
                        $(this).attr("title", "编辑");
                        $(this).html("<i class='fa fa-edit'></i>");
                        $("#phPreviewIntro").fadeIn();
                        $("#phEditableIntro").hide();
                    }
                });

                $("#formBaseInfo").submit(function () {
                    if (!$("#formBaseInfo").valid()) {
                        return false;
                    }
                    var postData = $("#formBaseInfo").serialize();
                    $.ajax({
                        url: "{:U('User/userinfo_ajax')}",
                        data: postData,
                        dataType: "json",
                        type: "post",
                        success: function (data) {
                            if (data.success != 1) {
                                messageBox.alert({ title: "保存失败", content: data.msg, sure: function () { window.location.reload(); } });
                            } else {
                                window.location.reload();
                            }
                        }
                    });
                    return false;
                });

            });

            $("#btnSavePhoto").click(function () {
                var photo = $('#userpic').val();
                if (photo == '') {
                    messageBox.alert({ content: "请先上传图片" });
                    return false;
                }

                var postData = { photo: photo };
                var url = "{:U('User/userphoto_ajax')}";
                $.post(url, postData, function (data) {
                    var vdata = eval(data);
                    if (vdata.success == 1) {
                        messageBox.alert({ content: "保存成功", sure: function () { window.location.reload(); } });
                    }
                }, 'json');

                return false;
            });

            function onYearChange(e) {
                var year = $("#ddlYears :selected").val();
                var month = $("#ddlMonths :selected").val();
                if (year != "" && month != "") {
                    var selected = new Date(year, month - 1);
                    bindDropDownListData("#ddlDays", 1, selected.daysInMonth());
                }
            }
        });
    </script>
</block>